package com.retallife.business.controller;


import com.retallife.business.exception.Result;
import com.retallife.business.pojo.Business.BusinessVo;
import com.retallife.business.pojo.Goods.GoodsVo;
import com.retallife.business.pojo.Login.LoginVo;
import com.retallife.business.service.BussinessService;
import com.retallife.business.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "厂商信息类")
@RequestMapping(method = {RequestMethod.POST, RequestMethod.GET})
public class BusinessController {

    @Autowired
    BussinessService bussinessService;

    @Autowired
    GoodsService goodsService;

    @ApiOperation(value = "查询厂商中的所有信息")
    @RequestMapping("FindAllBusiness")
    public List<BusinessVo> FindAllBusiness() {
        return bussinessService.FindAllBusiness();
    }

    @ApiOperation(value = "查询厂商的账号密码是否存在")
    @RequestMapping("FindBusiness")
    public Result FindBusiness(@RequestBody LoginVo LoginVo) {
        int result = bussinessService.FindBusiness(LoginVo);
        if (result > 0) {
            return Result.ok("登陆成功");
        }
        return Result.ok("登陆失败");
    }

    @ApiOperation(value = "查询某个厂商的信息")
    @RequestMapping("FindBusinessName")
    public List<BusinessVo> FindBusinessName(@RequestParam String businessName) {
      return bussinessService.FindBusinessName(businessName);
    }

    @ApiOperation(value = "查询某个厂商的商品信息")
    @RequestMapping("BusinessFindGoods")
    public List<GoodsVo> BusinessFindGoods(@RequestParam String goodsShopName) {
        System.out.println("goodsShopName:"+goodsShopName);
        return goodsService.BusinessFindGoods(goodsShopName);
    }
}
